/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author ali
 */
public class AjoutPromoForm extends org.apache.struts.action.ActionForm {
    
    
    private int formation;
    private String annee;
    private String key;
    private int grp;
    private int nbrperiode;
    private String[] periodestart;
    private String[] periodeend;

    public int getNbrperiode() {
        return nbrperiode;
    }

    public void setNbrperiode(int nbrperiode) {
        this.nbrperiode = nbrperiode;
    }

    public String[] getPeriodestart() {
        return periodestart;
    }

    public void setPeriodestart(String[] periodestart) {
        this.periodestart = periodestart;
    }

    public String[] getPeriodeend() {
        return periodeend;
    }

    public void setPeriodeend(String[] periodeend) {
        this.periodeend = periodeend;
    }

    public int getGrp() {
        return grp;
    }

    public void setGrp(int grp) {
        this.grp = grp;
    }
    
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Override
    public String toString() {
        String ret="";
        ret += "AjoutPromoForm{" + "formation=" + formation + ", annee=" + annee + ", key=" + key + ", grp=" + grp + ", nbrperiode=" + nbrperiode ;
        ret +=", periodestart=";
        for (String i : periodestart)
        ret += i+" , ";    
        ret += "|| periodeend=";
        for (String i : periodeend)
        ret += i+" , ";
        
        return ret;
    }

    
    public int getFormation() {
        return formation;
    }

    public void setFormation(int formation) {
        this.formation = formation;
    }

    public String getAnnee() {
        return annee;
    }

    public void setAnnee(String annee) {
        this.annee = annee;
    }

    /**
     * @return
     */

    public AjoutPromoForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getAnnee() == null || getAnnee().length() < 1 ) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
        
        if (getFormation() == 0 ) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
        
        if (getNbrperiode() == 0 ) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
        
       
    if ( periodestart.length != nbrperiode || periodeend.length != nbrperiode) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
    
        return errors;
    }
}
